<template>
    <el-dialog
        v-model="tenantDeleteDialogVisible"
        title="删除租户"
        width="20%"
        align-center
        :show-close="false"
        :close-on-click-modal="false"
    >
        是否确定删除？
        <template #footer>
            <div class="dialog-footer">
                <el-button @click="cancelDialog()">取 消</el-button>
                <el-button type="primary" :loading="deleteLoading" @click="submitDialog()">
                    确认
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script>
import {ElNotification} from "element-plus";
import {tenantInfoDelete, tenantInfoQuery} from "@/request/tenant";

export default {
    name: "TenantDeleteDialog",
    props: ['tenantDataForm'],
    data() {
        return {
            deleteLoading: false
        }
    },
    computed: {
        tenantDeleteDialogVisible() {
            return this.$store.state.tenantDeleteDialogVisible;
        },
        tenantSearchData() {
            return this.$store.state.tenantSearchData;
        }
    },
    methods: {
        cancelDialog() {
            this.$store.state.tenantDeleteDialogVisible = false;
        },
        submitDialog() {
            this.deleteLoading = true
            tenantInfoDelete(this.tenantDataForm).then(res => {
                if (res.code === '200') {
                    ElNotification({
                        title: 'Success',
                        message: res.message,
                        type: 'success'
                    });
                    tenantInfoQuery(this.tenantSearchData).then(res => {
                        this.$store.state.tenantDataList = res.data;
                    })
                    this.$store.state.tenantDeleteDialogVisible = false;
                }
                this.deleteLoading = false
            }).catch(res => {
                this.deleteLoading = true
            })
        }
    }
}
</script>

<style scoped lang="less">

</style>